Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
postcss-unique-selectors
Advanced tools
The postcss-unique-selectors npm package is a PostCSS plugin that removes duplicate CSS selectors within a rule. This helps in optimizing the CSS by ensuring that each selector is unique, which can reduce the size of the CSS file and improve maintainability.
Remove duplicate selectors
This feature removes duplicate selectors within a CSS rule. In the provided code sample, the duplicate 'a' selector is removed, resulting in 'a, b { color: red; }'.
const postcss = require('postcss');
const uniqueSelectors = require('postcss-unique-selectors');
const css = 'a, a, b { color: red; }';
postcss([uniqueSelectors])
.process(css)
.then(result => {
console.log(result.css); // Output: 'a, b { color: red; }'
});
cssnano is a modular minifier based on the PostCSS ecosystem. It includes a variety of optimizations, including the removal of duplicate selectors, making it a more comprehensive tool compared to postcss-unique-selectors.
postcss-discard-duplicates is another PostCSS plugin that removes duplicate rules and declarations. While it focuses on removing duplicate rules and declarations, it can be used in conjunction with postcss-unique-selectors for more thorough CSS optimization.
Ensure CSS selectors are unique.
With npm do:
npm install postcss-unique-selectors --save
Selectors are sorted naturally, and deduplicated:
h1,h3,h2,h1 {
color: red
}
h1,h2,h3 {
color: red
}
See the PostCSS documentation for examples for your environment.
See CONTRIBUTORS.md.
MIT © Ben Briggs
FAQs
Ensure CSS selectors are unique.
The npm package postcss-unique-selectors receives a total of 6,715,992 weekly downloads. As such, postcss-unique-selectors popularity was classified as popular.
We found that postcss-unique-selectors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.